<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of AbstractAction
 *
 * @author Jensen
 */
abstract class AbstractAction {
    public abstract function run();
    
    protected function getFilterValues() {
        global $filters;
        // set filters
        foreach( $filters as &$filter ){
            if(strpos($filter['value'], "-") !== false ){
                $filter['value'] = explode(" ", $filter['value']);
                foreach( $filter['value'] as &$item ){
                    $itemArr = array();
                    list($itemArr['text'],$itemArr['value']) = explode("-", $item );
                    $item = $itemArr;
                }
            }
            else{
                $filter['value'] = explode(" ", $filter['value']);
                foreach( $filter['value'] as &$item ){
                    $itemArr = array();
                    $itemArr['text'] = $item;
                    $itemArr['value'] = $item;
                    $item = $itemArr;
                }
            }
        }
        
        return $filters;
    }
    
    protected function getMovieTypeNameById( $id ){
        global $filters;
        
        return $filters['movietype']['value'][$id]['text'];
    }
    
    protected function getLargeImgUrl( $imgUrl ){
        // set large images
        $smallImgUrl = $imgUrl;
        $smallImgFileName = basename( $smallImgUrl );
        $imgUrlPrefix = str_replace($smallImgFileName, "", $smallImgUrl);
        $largeImgFileName = str_replace("m_", "", $smallImgFileName);
        return $imgUrlPrefix.$largeImgFileName;
    }
    
    /**
     * get single dao instance 
     * 
     * @global name $name
     * @param name $name
     * @return \name 
     */
    protected function getDao( $name ){
        global $$name;
		
		if( isset($$name) )
			return $$name;
		else 
		{
			$$name = new $name();
			return $$name;
		}
    }
    
}

?>
